package com.twu.biblioteca;

public class LoginController {

    public void Login(String id, String password) {
        prompt(checkPassword(id, password));
    }

    private void prompt(boolean loginStatus) {
        if (loginStatus) {
            System.out.println("Login Successful! Hello " + BibliotecaApp.legalUser.getName() + "!");
        } else {
            System.out.println("Sorry, User Id or Password Wrong!");
        }
    }

    private boolean checkPassword(String id, String password) {
        if (UserList.getUserList().get(id) != null) {
            if (password.equals(UserList.getUserList().get(id).getPassword())) {
                BibliotecaApp.legalUser = UserList.getUserList().get(id);
                return true;
            }
        }
        return false;
    }

    public boolean checkLogin() {
        return (BibliotecaApp.legalUser == null) ? false : true;
    }
}
